﻿/*
 * Last review by   : Yaser
 * Last review date : JUL-21-09 
 */
using System;

namespace ERP.Business.DataTypes.Employee.Attendance
{
    /// <summary>
    /// Time card entry
    /// </summary>
    [System.Runtime.Serialization.DataContract]
    [Serializable]
    [System.Runtime.Serialization.KnownType(typeof(TimeCardEntry))]
    public class TimeCardEntry : BaseTypes.BaseType
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="TimeCardEntry"/> class.
        /// </summary>
        public TimeCardEntry() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="TimeCardEntry"/> class.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <param name="dir">The dir.</param>
        public TimeCardEntry(DateTime date, Constants.CheckDirection dir)
        {
            CheckDate = date;
            Direction = dir;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the check date.
        /// </summary>
        /// <value>The check date.</value>
        [System.Runtime.Serialization.DataMember]
        public DateTime CheckDate
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the direction.
        /// </summary>
        /// <value>The Check direction <see cref="Constants.CheckDirection"/>.</value>
        [System.Runtime.Serialization.DataMember]
        public Constants.CheckDirection Direction
        {
            get;
            set;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Equals function.
        /// Since the ID is not the PK for this type; the comparison will be regarding both CheckDate and CheckDirection.
        /// </summary>
        /// <param name="obj">Object to compare</param>
        /// <returns>true if same date and same direction</returns>
        public override bool Equals(object obj)
        {
            if (ERP.Framework.Components.Utilities.ComparingHelper.ComapringManager.CompareTypes(this, obj)
                 && CheckDate.Equals(((TimeCardEntry)obj).CheckDate) && Direction.Equals(((TimeCardEntry)obj).Direction))
                return true;
            return false;
        }

        /// <summary>
        /// Compare objects
        /// </summary>
        /// <param name="x">object 1</param>
        /// <param name="y">object 2</param>
        /// <returns>Compare result</returns>
        public override int Compare(object x, object y)
        {
            if (ERP.Framework.Components.Utilities.ComparingHelper.ComapringManager.CompareTypes(x, y))
                return ((TimeCardEntry)x).CheckDate.CompareTo(((TimeCardEntry)y).CheckDate);
            return -1;
        }

        /// <summary>
        /// Clone current object
        /// </summary>
        /// <returns>Cloned object</returns>
        public override object Clone()
        {
            TimeCardEntry tc = new TimeCardEntry();
            tc.ID = ID;
            tc.CheckDate = CheckDate;
            tc.Direction = Direction;
            return tc;
        }

        #endregion
    }
}
